package com.slipper.scheduled;

import com.slipper.PaasContext;
import com.slipper.system.schedule.bo.ScheduleBO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RunnableFactory {
    private static final Logger logger = LoggerFactory.getLogger(RunnableFactory.class);

    public static Runnable createRunnable(ScheduleBO schedule) {
        for (IScheduledRunnable runnable : PaasContext.getBeans(IScheduledRunnable.class).values()) {
            if (runnable.supports(schedule)) {
                return runnable.createRunnable(schedule);
            }
        }

        logger.error("不支持的调度类型【{}】。", schedule.getBusinessType());
        throw new RuntimeException("不支持的调度类型【" + schedule.getBusinessType() + "】。");
    }
}
